package com.wosai.medical.hospital.demo.controller.inpatient;

import com.google.common.collect.Lists;
import com.wosai.medical.hospital.demo.common.DataResult;
import com.wosai.medical.hospital.demo.controller.BaseController;
import com.wosai.medical.hospital.demo.controller.check.response.InspectReportsDetail;
import com.wosai.medical.hospital.demo.controller.inpatient.response.Deposit;
import com.wosai.medical.hospital.demo.controller.inpatient.response.Pay;
import com.wosai.medical.hospital.demo.controller.inpatient.response.Record;
import com.wosai.medical.hospital.demo.controller.patient.response.FeeOrder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @desc
 * @auther 韦湘平
 * @date 2020/2/20 11:15 上午
 */

@Slf4j
@Api(tags = "住院")
@RestController
@RequestMapping("/hospital/inpatient")
public class InpatientController extends BaseController {

    /**
     * 6.1. 住院记录查询
     *
     * @param apiAppId    接入账号
     * @param apiVersion  接口版本号
     * @param apiStamp    时间戳
     * @param apiSign     参数签名
     * @param patientCode
     * @return 获取患者信息
     */
    @ApiOperation("6.1. 住院记录查询")
    @GetMapping("/patient/{patientCode}")
    public RespResult<DataResult> getinspectReport(
            //接入账号(app_id)
            @RequestHeader("api_app_id") final String apiAppId,
            //接口版本号(采用正整数描述)
            @RequestHeader("api_version") final Integer apiVersion,
            //时间戳(13位到毫秒)
            @RequestHeader("api_stamp") final Long apiStamp,
            //参数签名
            @RequestHeader("api_sign") final String apiSign,
            //检验报告代码(唯一标识)
            @PathVariable final String patientCode
    ) {
        return action(new Process<DataResult>() {
            @Override
            public String getAppId() {
                return apiAppId;
            }

            @Override
            public Integer getVersion() {
                return apiVersion;
            }

            @Override
            public Long getStamp() {
                return apiStamp;
            }

            @Override
            public String getSign() {
                return apiSign;
            }

            @Override
            public Map<String, Serializable> getParams() {
                return new HashMap<String, Serializable>(2) {
                    {
                        put("patientCode", patientCode);
                    }
                };
            }

            @Override
            public DataResult handler() {
                ///TODO: 业务处理
                List<Serializable> records = Lists.newArrayList(
                        Record.builder()
                                .code("112121221")
                                .number("2131221")
                                .dept(Record.Dept.builder()
                                        .code("ssss")
                                        .name("阿斯顿发送")
                                        .build())
                                .doctor(Record.Doctor.builder()
                                        .code("ddsssd")
                                        .name("sdddssd")
                                        .build())
                                .area(Record.Area.builder()
                                        .code("dssddssd")
                                        .name("Ad-11")
                                        .build())
                                .status(0)
                                .inDate("2020-03-01")
                                .outDate("2020-03-04")
                                .totalAmount(50000l)
                                .description("dddd")
                                .build()
                );

                return DataResult.builder().totals(1L).rows(records).build();
            }
        });
    }

    /**
     * 6.2. 住院押金查询
     * @param apiAppId      接入账号
     * @param apiVersion    接口版本号
     * @param apiStamp      时间戳
     * @param apiSign       参数签名
     * @param inpatientCode 门诊流水号
     * @return 获取患者信息
     */
    @ApiOperation("6.2. 住院押金查询")
    @GetMapping("/{inpatientCode}/deposit")
    public RespResult<Deposit> getFeeDetail(
            //接入账号(app_id)
            @RequestHeader("api_app_id") final String apiAppId,
            //接口版本号(采用正整数描述)
            @RequestHeader("api_version") final Integer apiVersion,
            //时间戳(13位到毫秒)
            @RequestHeader("api_stamp") final Long apiStamp,
            //参数签名
            @RequestHeader("api_sign") final String apiSign,
            //住院代码(患者住院唯一标识)
            @PathVariable final String inpatientCode
    ) {
        return action(new Process<Deposit>() {
            @Override
            public String getAppId() {
                return apiAppId;
            }

            @Override
            public Integer getVersion() {
                return apiVersion;
            }

            @Override
            public Long getStamp() {
                return apiStamp;
            }

            @Override
            public String getSign() {
                return apiSign;
            }

            @Override
            public Map<String, Serializable> getParams() {
                return new HashMap<String, Serializable>(2) {
                    {
                        put("inpatientCode", inpatientCode);
                    }
                };
            }

            @Override
            public Deposit handler() {
                ///TODO: 业务处理
                return Deposit.builder()
                        .totalAmount(200000L)
                        .paidAmount(300000L)
                        .surplusAmount(100000L)
                        .build();
            }
        });
    }

    /**
     * 6.3. 住院押金补缴支付
     *
     * @param apiAppId   接入账号
     * @param apiVersion 接口版本号
     * @param apiStamp   时间戳
     * @param apiSign    参数签名
     * @param req
     * @return 获取患者信息
     */
    @ApiOperation("6.3. 住院押金补缴支付")
    @PostMapping("/order/pay")
    public RespResult<Pay> getFeeDetail(
            //接入账号(app_id)
            @RequestHeader("api_app_id") final String apiAppId,
            //接口版本号(采用正整数描述)
            @RequestHeader("api_version") final Integer apiVersion,
            //时间戳(13位到毫秒)
            @RequestHeader("api_stamp") final Long apiStamp,
            //参数签名
            @RequestHeader("api_sign") final String apiSign,

            @RequestBody(required = true) final Map<String, Serializable> req
    ) {
        return action(new Process<Pay>() {
            @Override
            public String getAppId() {
                return apiAppId;
            }

            @Override
            public Integer getVersion() {
                return apiVersion;
            }

            @Override
            public Long getStamp() {
                return apiStamp;
            }

            @Override
            public String getSign() {
                return apiSign;
            }

            @Override
            public Map<String, Serializable> getParams() {
                return req;
            }

            @Override
            public Pay handler() {
                ///TODO: 业务处理
                return Pay.builder()
                        .hisOrderCode("1122111")
                        .balance(250000L)
                        .receiptNo("ddd")
                        .payCertificate(null)
                        .build();
            }
        });
    }

}
